package net.yla.smartbus.module.controller.web.ba.right.role;

import net.yla.smartbus.core.api.ApiResult;
import net.yla.smartbus.core.base.BaseController;
import net.yla.smartbus.core.constants.UserRoleEnum;
import net.yla.smartbus.module.ba.right.right.service.RightsService;
import net.yla.smartbus.module.ba.right.roles.form.RoleForm;
import net.yla.smartbus.module.ba.right.roles.form.RolesForm;
import net.yla.smartbus.module.ba.right.roles.query.QueryOfCount;
import net.yla.smartbus.module.ba.right.roles.query.QueryOfRoles;
import net.yla.smartbus.module.ba.right.roles.query.QueryOfView;
import net.yla.smartbus.module.ba.right.roles.service.RolesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Date: 2020-08-12 15:54
 * @Author: Being Nobody
 * @Version: 1.0
 */
@RestController
@RequestMapping("/api/web/role")
public class RoleController extends BaseController {

    @Autowired
    private RolesService rolesService;

    @Autowired
    private RightsService rightsService;

    /**
     * 1获取符合条件角色的记录数
     *
     * @param queryOfCount
     * @return
     */
    @PostMapping("/count")
    public ApiResult queryOfCount(@RequestBody QueryOfCount queryOfCount) {
        return success(rolesService.queryOfCount(queryOfCount));
    }

    /**
     * 2获取符合条件角色的记录集
     *
     * @param queryOfRoles
     * @return
     */
    @PostMapping("/query")
    public ApiResult queryOfRole(@RequestBody QueryOfRoles queryOfRoles) {
        rolesService.userRoleEvaluation(UserRoleEnum.USER_ROLE_SELECT, getToken(), getIpAddress());
        // 获取所有菜单
        return success(rolesService.queryOfRoles(queryOfRoles));
    }

    /**
     * 3 查看角色的详情
     *
     * @param queryOfView
     * @return
     */
    @PostMapping("/view")
    public ApiResult rolesOfView(@RequestBody QueryOfView queryOfView) {
        // 获取所有菜单
        return success(rolesService.rolesOfView(queryOfView));
    }

    /**
     * 4 保存角色信息
     *
     * @param rolesForm
     * @return
     */
    @PostMapping("/save")
    public ApiResult rolesOfView(@RequestBody RolesForm rolesForm) {
        // 获取所有菜单
        return success(rolesService.save(rolesForm));
    }

    /**
     * 5删除角色信息
     *
     * @param query
     * @return
     */
    @PostMapping("/del")
    public ApiResult del(@RequestBody @Validated QueryOfView query) {
        rolesService.userRoleEvaluation(UserRoleEnum.USER_ROLE_DELETE, getToken(), getIpAddress());
        // 获取所有菜单
        return success(rolesService.del(query));
    }

    /**
     * 6多表查询角色信息
     *
     * @param queryOfRoles
     * @return
     */
    @PostMapping("/query/admin")
    public ApiResult selectByAdmin(QueryOfRoles queryOfRoles) {
        return success(rolesService.selectByAdmin(queryOfRoles));
    }

    /**
     * 6 添加角色信息
     *
     * @param form
     * @return
     */
    @PostMapping("/add")
    public ApiResult add(@RequestBody @Validated RoleForm form) {
        rolesService.userRoleEvaluation(UserRoleEnum.USER_ROLE_INSERT, getToken(), getIpAddress());
        return success(rolesService.add(form));
    }

    /**
     * 6 添加角色信息
     *
     * @param form
     * @return
     */
    @PostMapping("/update")
    public ApiResult update(@RequestBody @Validated RoleForm form) {
        rolesService.userRoleEvaluation(UserRoleEnum.USER_ROLE_UPDATE, getToken(), getIpAddress());
        return success(rolesService.update(form));
    }

    /**
     * 6多表查询角色信息
     *
     * @param adminId
     * @return
     */
    @PostMapping("/query/adminId")
    public ApiResult roles(Integer adminId) {
        return success(rolesService.roles(adminId));
    }

    /**
     * 6 添加角色信息
     *
     * @param form
     * @return
     */
    @PostMapping("/platformIds")
    public ApiResult platformIds(@RequestBody @Validated RolesForm form) {
        return success(rolesService.platformIds(form));
    }

    /**
     * 6 添加角色信息
     *
     * @param form
     * @return
     */
    @PostMapping("/menuIds")
    public ApiResult menuIds(@RequestBody @Validated RolesForm form) {
        return success(rolesService.menuIds(form));
    }

}
